package io.renren.wh.merchant.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.wh.interfaces.entity.InterfacesEntity;
import io.renren.wh.interfaces.service.InterfacesService;
import io.renren.wh.merchant.entity.InfoEntity;
import io.renren.wh.merchant.entity.InfoFaceRelation;
import io.renren.wh.merchant.service.InfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author liulinqiu
 * @email liulinqiu1997@163.com
 * @date 2020-07-19 16:04:27
 */

@Api(value = "商户信息接口",tags = "商户信息接口")
@RestController
@RequestMapping("wh/info")
public class InfoController {
    @Autowired
    private InfoService infoService;

    @Autowired
    InterfacesService interfacesService;

    @ApiOperation(value = "绑定商户费率", notes = "绑定商户费率", httpMethod = "POST")
    @RequestMapping("/infofacerelation")
    @RequiresPermissions("wh:inforate:list")
    public R addMerchaninfoInterfacesRelation(@RequestBody List<InfoFaceRelation> vo){
        if(vo!=null){
            infoService.insertInterfacesRelation(vo);
        }
        return R.ok();
    }

    /**
     * 查询所有接口信息
     */
    @ApiOperation(value = "查询所有接口信息", notes = "查询所有接口信息", httpMethod = "GET")
    @RequestMapping("/interface")
    @RequiresPermissions("wh:infoface:list")
    public R faceList(Integer id){
        List<InterfacesEntity> list = interfacesService.faceList(id);
        PageUtils pageUtils = new PageUtils(list,10,10,10);

        return R.ok().put("page",pageUtils);

    }



    /**
     * 列表
     */
    @ApiOperation(value = "商户信息列表", notes = "商户信息列表", httpMethod = "GET")
    @RequestMapping("/list")
    @RequiresPermissions("wh:info:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = infoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "根据id查询商户信息", notes = "根据id查询商户信息", httpMethod = "GET")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("wh:info:info")
    public R info(@PathVariable("id") Integer id){
		InfoEntity info = infoService.getById(id);

        return R.ok().put("info", info);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增商户信息", notes = "新增商户信息", httpMethod = "POST")
    @RequestMapping("/save")
    @RequiresPermissions("wh:info:save")
    public R save(@RequestBody InfoEntity info){
		infoService.saveAndCreateAccount(info);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改商户信息", notes = "修改商户信息", httpMethod = "PUT")
    @RequestMapping("/update")
    @RequiresPermissions("wh:info:update")
    public R update(@RequestBody InfoEntity info){
		infoService.updateById(info);

        return R.ok();
    }

    @RequestMapping("/insert")
    //@RequiresPermissions("hy:info:update")
    public R Insert(@RequestBody  InfoEntity info){
        infoService.insertFaceId(info);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "根据id删除商户信息", notes = "根据id删除商户信息", httpMethod = "DELETE")
    @RequestMapping("/delete")
    @RequiresPermissions("wh:info:delete")
    public R delete(@RequestBody Integer[] ids){
		infoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
